<?php

namespace App;

use Composer\Package\Package;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;

/**
 * App\CoursePackageXCourse
 *
 * @property int $id
 * @property int $course_package_id 套餐id
 * @property int $course_id 课程id
 * @property int $is_must 是否必选
 * @property float $discount_price 优惠价格
 * @property \Illuminate\Support\Carbon|null $created_at
 * @property \Illuminate\Support\Carbon|null $updated_at
 * @method static \Illuminate\Database\Eloquent\Builder|\App\CoursePackageXCourse newModelQuery()
 * @method static \Illuminate\Database\Eloquent\Builder|\App\CoursePackageXCourse newQuery()
 * @method static \Illuminate\Database\Eloquent\Builder|\App\CoursePackageXCourse query()
 * @method static \Illuminate\Database\Eloquent\Builder|\App\CoursePackageXCourse whereCourseId($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\CoursePackageXCourse whereCoursePackageId($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\CoursePackageXCourse whereCreatedAt($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\CoursePackageXCourse whereDiscountPrice($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\CoursePackageXCourse whereId($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\CoursePackageXCourse whereIsMust($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\CoursePackageXCourse whereUpdatedAt($value)
 * @mixin \Eloquent
 * @method static bool|null forceDelete()
 * @method static \Illuminate\Database\Query\Builder|\App\CoursePackageXCourse onlyTrashed()
 * @method static bool|null restore()
 * @method static \Illuminate\Database\Query\Builder|\App\CoursePackageXCourse withTrashed()
 * @method static \Illuminate\Database\Query\Builder|\App\CoursePackageXCourse withoutTrashed()
 * @property int $remain_num 剩余数量
 * @property int $sold_num 售出数量
 * @method static \Illuminate\Database\Eloquent\Builder|\App\CoursePackageXCourse whereRemainNum($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\CoursePackageXCourse whereSoldNum($value)
 * @property \Illuminate\Support\Carbon|null $deleted_at
 * @method static \Illuminate\Database\Eloquent\Builder|\App\CoursePackageXCourse whereDeletedAt($value)
 */
class CoursePackageXCourse extends Model
{
    use SoftDeletes;
    public static function getCoursePackages($course_id){
        if (!$course_id)
            return [];
        $result = [];
        $data = self::whereCourseId($course_id)->get();
        if ($data){
            foreach ($data as $item){
                $tmp=CoursePackage::whereId($item->course_package_id)->first();
                if ($tmp)
                    array_push($result,$tmp);
            }
        }
        return $result;
    }
    public static function getPackagesCourse($package_id){
        if (!$package_id)
            return [];
        $data = self::whereCoursePackageId($package_id)->get();
        if ($data){
            foreach ($data as $item){
                $item->course_info =Course::getCourseInfo($item->course_id);
            }
        }
        return $data;
    }
}
